#pragma once

#include <vector>
#include <glm\glm.hpp>
#include <GL\glew.h>
#include <assimp\Importer.hpp>
#include <assimp\postprocess.h> 
#include <assimp\scene.h>


#include "ogldev_texture.h"
#include "ogldev_math_3d.h"


struct Vertex
{
	Vector3f m_pos;
	Vector2f m_tex;
	Vector3f m_normal;

	Vertex() {}

	Vertex(const Vector3f& pos, const Vector2f& tex, const Vector3f& normal)
	{
		m_pos = pos;
		m_tex = tex;
		m_normal = normal;
	}
};



class Mesh
{
	public:
		Mesh();

		~Mesh();

		bool LoadMesh(const std::string& Filename);

		void Render();

	private:
		bool InitFromScene(const aiScene* pScene, const std::string& Filename);
		void InitMesh(unsigned int Index, const aiMesh* paiMesh);
		bool InitMaterials(const aiScene* pScene, const std::string& Filename);
		void Clear();
		#define INVALID_MATERIAL 0xFFFFFFFF

		struct MeshEntry 
		{
				MeshEntry();

				~MeshEntry();

				void Init(const std::vector<Vertex>& Vertices,
					const std::vector<unsigned int>& Indices);

				GLuint VB;
				GLuint IB;
				unsigned int NumIndices;
				unsigned int MaterialIndex;
		};

		std::vector<MeshEntry> m_Entries;
		std::vector<Texture*> m_Textures;
};

